package com.cjack.frenchexcel.config;

import com.cjack.frenchexcel.exception.CommonException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class AjaxResult {

    private final static Integer DEFAULT_SUCCESS_CODE = 200;
    private final static String DEFAULT_SUCCESS_MSG = "请求成功";

    private Integer code;
    private String msg;
    private Object data;

    public static AjaxResult SUCCESS(){
        return new AjaxResult( DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MSG, null);
    }

    public static AjaxResult SUCCESS( String msg){
        return new AjaxResult( DEFAULT_SUCCESS_CODE, msg, null);
    }

    public static AjaxResult SUCCESS( Object data){
        return new AjaxResult( DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MSG, data);
    }

    public static AjaxResult ERROR( Integer code, String msg){
        return new AjaxResult( code, msg, null);
    }

    /**
     * 返回系统错误
     * @return
     */
    public static AjaxResult ERROR(){
        CommonException exception = new CommonException();
        return new AjaxResult( exception.getCode(), exception.getMessage(), null);
    }
}
